home *** CD-ROM | disk | FTP | other *** search
- //
- // flvlist.js
- // firefox
- //
- // Created by Zak on 2008-06-12.
- // Copyright 2008 Ant.com. All rights reserved.
- //
-
- var AntFlvList =
- {
- listBox: null,
- flvLinks: new AntArray(),
-
- init: function ()
- {
- var self = AntFlvList;
- },
-
- /**
- * Display the notification popup box
- * @param flvLink A flvLink object
- */
- notify: function (flvLink)
- {
- var listener =
- {
- observe: function(subject, topic, data)
- {
- if (topic == "alertclickcallback")
- AntFlvList.download(flvLink);
- }
- };
-
- try
- {
- var title = AntLang.getFormatString("AntFlvList.NotificationTitle", flvLink.origin);
- var text = AntLang.getFormatString("AntFlvList.NotificationText", flvLink.name);
- var alertsService = AntLib.CCSV("@mozilla.org/alerts-service;1", "nsIAlertsService");
-
- alertsService.showAlertNotification("chrome://antbar/skin/logo.png", title, text, true, flvLink, listener);
- }
- catch (e)
- {
- AntLib.toLog("Cannot notify flvLInk = " + flvLink.url + " ex = " + e);
- }
- },
-
- /**
- * Download a file
- * @param if true the Firefox download manager won't be opened
- */
- download: function (flvLink, doNotOpen)
- {
- var self = AntFlvList;
- var path = AntDownloadManager.downloadFlv(flvLink, doNotOpen);
-
- AntLib.toLog("Downloading : " + flvLink.url);
- },
-
- /**
- * getFlvLinkByUrl: return the flvLink object matching the url
- * @param url to match
- */
- getFlvLinkByUrl: function (url)
- {
- var self = AntFlvList;
- for (var i = 0; i < self.flvLinks.length; i++)
- if (self.flvLinkCompare(self.flvLinks[i], {url: url}))
- return self.flvLinks[i];
-
- return null;
- },
-
- /*
- * Simple compare function for AntFlvLink objects
- * @return true if a and b are equal, false if not
- */
- flvLinkCompare: function (a, b)
- {
- return a.url == b.url;
- },
-
- /**
- * Drop the global this.flvLinks and regenerate the UI list
- */
- clean: function ()
- {
- var self = AntFlvList;
- self.flvLinks = new AntArray();
- self.refreshDisplay();
- },
-
- /**
- * Regenerate the UI list (drop and append loop)
- */
- refreshDisplay: function ()
- {
- var self = AntFlvList;
- AntFlvUi.removeAll();
- for (var i = 0; i < self.flvLinks.length; i++)
- {
- if (self.flvLinks[link].origin && self.flvLinks[link].url && self.flvLinks[link].name)
- AntFlvUi.appendItem(self.flvLinks[link].origin, self.flvLinks[link].url, self.flvLinks[link].name, i);
- }
- },
-
- /**
- * Callback: fired from the context menu "Rename"
- */
- onPopupRename: function (event)
- {
- var self = AntFlvList;
- var url = document.popupNode.childNodes[1].getAttribute('label');
- var name = document.popupNode.childNodes[2].getAttribute('label');
- var flvlink = self.getFlvLinkByUrl(url);
-
- name = name.replace(/_/g,' ');
- var newName = prompt(AntLang.getFormatString("AntFlvList.PromptRenameText", name), name);
-
- if (!newName)
- return;
-
- if (!newName.match(/^[\w -]+$/i))
- {
- alert(AntLang.getString("AntFlvList.InvalidFileName"));
- return ;
- }
- if (flvlink)
- {
- flvlink.name = newName.replace(/[ ]/g,'_');
- document.popupNode.childNodes[2].setAttribute('label', newName);
- }
-
- },
-
- }
-